package com.jt.service;

import com.jt.mapper.User2Mapper;
import com.jt.pojo.User2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.DigestUtils;

import java.util.List;

/**
 * @author tang
 * @data 2021/9/4
 * @apiNode
 */
@Service
public class User2ServiceImpl implements User2Service{
    @Autowired
    private User2Mapper user2Mapper;

    @Override
    public List<User2> getAll() {
        return user2Mapper.selectList(null);
    }

    @Override
    public void deleteUserById(Integer id) {
        user2Mapper.deleteById(id);
    }

    @Override
    public User2 getById(Integer id) {
        return user2Mapper.selectById(id);
    }

    @Override
    public void updateUser(User2 user2) {
        user2Mapper.updateById(user2);
    }

    @Override
    public void saveUser(User2 user2) {
        String password = user2.getPassword();
        password = DigestUtils.md5DigestAsHex(password.getBytes());
        user2.setPassword(password).setStatus(true);
        user2Mapper.insert(user2);
    }

    @Override
    public void updateStutas(User2 user2) {
        user2Mapper.updateById(user2);
    }
}
